package extension

import android.content.res.Resources
import android.util.Log
import android.util.TypedValue
import kotlin.math.roundToInt

val Number.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        toFloat(),
        Resources.getSystem().displayMetrics
    )

val Number.dip
    get() = this.dp.roundToInt()
//    get() = ceil(this.dpf).toInt()

val Number.sp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_SP,
        toFloat(),
        Resources.getSystem().displayMetrics
    )

inline fun ifNotNull(vararg value: Any?, block: () -> Unit) {
    value.forEach {
        it ?: return
    }
    block()
}

fun log(log: String,tag: String? = "") {
    Log.i(tag, log)
}